local zhanglun = fk.CreateSkill{
  name = "rainveil__zhanglun",
  tags = {
    Skill.Compulsory
  }
}

Fk:loadTranslationTable{
  ["rainveil__zhanglun"] = "彰论",
  [":rainveil__zhanglun"] = "锁定技，你第X次使用或打出牌后，若此牌点数为X，你摸X张牌。",
  ["@rainveil__zhanglun"] = "彰论",

  ["$rainveil__zhanglun1"] = "虽穷不处亡国之势，虽贫不受污君之禄。",
  ["$rainveil__zhanglun2"] = "但因明主未遇，故潜居抱道以待其时。",
  ["$rainveil__zhanglun3"] = "知命者待时而举，岂曰时无英雄乎？",
  ["$rainveil__zhanglun4"] = "太公七十而不自达，孙叔敖三去相而不自悔。",
}

zhanglun:addAcquireEffect(function (self, player, is_start)
  local room = player.room
  local use_times = 0
  room.logic:getEventsByRule(GameEvent.UseCard, 1, function (e)
    if e.data.from == player then
      use_times = use_times + 1
    end
  end)
  room.logic:getEventsByRule(GameEvent.RespondCard, 1, function (e)
    if e.data.from == player then
      use_times = use_times + 1
    end
  end)
  room:setPlayerMark(player, "@rainveil__zhanglun", use_times)
end)

zhanglun:addLoseEffect(function (self, player, is_start)
  local room = player.room
  room:setPlayerMark(player, "@rainveil__zhanglun", 0)
end)

zhanglun:addEffect(fk.CardUseFinished, {
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(zhanglun.name) and target == player
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@rainveil__zhanglun", 1)
  end,
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(zhanglun.name) and target == player
  end,
  on_use = function (self, event, target, player, data)
    if player:getMark("@rainveil__zhanglun") == data.card.number then
      player:drawCards(data.card.number, zhanglun.name)
    end
  end
})

zhanglun:addEffect(fk.CardRespondFinished , {
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(zhanglun.name) and target == player
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@rainveil__zhanglun", 1)
  end,
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(zhanglun.name) and target == player
  end,
  on_use = function (self, event, target, player, data)
    if player:getMark("@rainveil__zhanglun") == data.card.number then
      player:drawCards(data.card.number, zhanglun.name)
    end
  end
})

return zhanglun
